package com.zqs.compareface.server.commit;

import com.zqs.compareface.dao.UserData;
import com.zqs.compareface.dao.UserFaceData;
import com.zqs.compareface.entity.UserImage;
import com.zqs.compareface.myenum.Judges;
import com.zqs.compareface.server.apiserver.BaiduApiJudge;
import com.zqs.compareface.server.imageProcess.SaveOrConvertFaceImage;
import com.zqs.compareface.utils.impl.ResultUtil;
import com.zqs.compareface.utils.impl.Timer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;

import java.time.Instant;
import java.util.Date;

/**
 * @Program: face
 * @Description:
 * @Author: zqs
 * @Create： 2021-08-09-22:17
 */
public class CommitApiOrLocal {
    protected static final Log log = LogFactory.getLog(CommitApiOrLocal.class);

    /**
     * 准备传参数据，调用commitToBaiduApi()方法提交到百度
     * @param Base64Code
     * @param userid
     */
    public static void preparingData(String Base64Code,String userid){
        UserImage userImage = new UserImage(userid, "user", Base64Code);
        UserData userData = new UserFaceData(userImage);
        if(true){
            commitToBaiduApi(userData);
        }else {
//            CommitApiOrLocal.commitToBaiduApi(userData);
        }
    }

    /**
     * 提交到百度API
     * @param userData
     */
    public static void commitToBaiduApi(UserData userData) {
            String imageTypes = "BASE64";
            Timer.time = Instant.now();
            JSONObject result = BaiduApiJudge.faceToFaceCompare(userData, imageTypes);
            Boolean compareResult = ResultUtil.isOrNot(result);
            if (!compareResult) {
                log.info(Judges.ISNOT.getJudges());
            } else {
                log.info(Judges.IS.getJudges());
            }
            //TODO 线程停止
    }
}
